package 剑指Offer._2130;

import general_class.TreeNode;
import sun.misc.BASE64Decoder;

import java.io.IOException;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/8/16 20:57
 * 树的子结构
 * 算法：树
 * 遍历树 A 的节点，使用 isSubStructure 方法
 * 如果遍历到的节点值与树 B 的根节点相等，那么就开始 check
 * check 方法中，是一层一层比对过去
 */
public class _26 {
    public static void main(String[] args) throws IOException {
        String s = "a = 1";
        System.out.println(s.indexOf("="));
        BASE64Decoder decoder = new BASE64Decoder();
        System.out.println(new String(decoder.decodeBuffer(s), "utf-8"));
        System.out.println(s.substring(s.indexOf("=") + 1));
    }

    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (A == null || B == null) return false;
        if (A.val == B.val && check(A, B)) return true;
        return isSubStructure(A.left, B) || isSubStructure(A.right, B);
    }
    public boolean check(TreeNode a, TreeNode b) {
        if (a == null || b == null) return b == null;
        if (a.val != b.val) return false;
        return check(a.left, b.left) && check(a.right, b.right);
    }

}
